﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StartStop.Helpers
{
    public class User
    {
        public const string LiveConnectionString = "data source=v2.startstop.me;initial catalog=startstop;persist security info=True;user id=sa;password=PASSWORD;";

        public static Int64 LookUpUserIDFromGUID(Guid UserGuid)
        {
            Int64 _return = -1;

            string sqlreturn = Sql.ExecuteScalar("select UserID from ssUsers where UserGUID = @passedvalue", UserGuid.ToString());
            if (sqlreturn != "")
            {
                _return = Int64.Parse(sqlreturn); 
            }

            return _return; 
        }


        public static bool CheckValidatedUserInfo(ref ServiceResources.ValidatedUserInfo oUserInfo)
        {
            // This should check to see if the userinfo has been passed with an id or guid
            bool _return = false;
            if (oUserInfo.UserID != null)
            {
                _return = true;
            }
            else
            {
                if (oUserInfo.UserGUID != null)
                {
                    // Look up the user from a GUID. 
                    oUserInfo.UserID = LookUpUserIDFromGUID(oUserInfo.UserGUID);
                    return true; 
                }
            }

            return _return; 
        }
    }
}
